﻿<DxTreeView @ref="@treeView" 
            CssClass="app-sidebar" 
            ExpandButtonIconCssClass="demo-icon-expand" 
            CollapseButtonIconCssClass="demo-icon-collapse"
            AllowSelectNodes="true" 
            NodeExpandCollapseAction="TreeViewNodeExpandCollapseAction.NodeClick"
            BeforeExpand="@BeforeExpand"
            SelectionChanged="@SelectionChanged">
    <Nodes>
        <DxTreeViewNode Text="中天钢铁" NavigateUrl="">
        </DxTreeViewNode>
        <DxTreeViewNode Text="准发计划" >
            <Nodes>
                <DxTreeViewNode Text="可编计划查询" NavigateUrl="GridSelectionMultiple" ></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode> 
    </Nodes>
</DxTreeView>

@code {
    DxTreeView treeView;

    protected void SelectionChanged(TreeViewNodeEventArgs e) {
        if (e.NodeInfo.IsLeaf) {
            var parentInfo = e.NodeInfo.Parent;
            if (parentInfo != null) {
                var parentSiblingNodesInfo = treeView.GetNodesInfo(n => !n.IsLeaf && n.Level == parentInfo.Level && !string.Equals(n.Text, parentInfo.Text));
                foreach (var nodeInfo in parentSiblingNodesInfo)
                    treeView.SetNodeExpanded(n => string.Equals(n.Text, nodeInfo.Text), false);
            }
            else
                treeView.CollapseAll();
        }
    }

    protected void BeforeExpand(TreeViewNodeCancelEventArgs e) {
        if (!e.CausedByAPI)
            treeView.CollapseAll();
    }
}